import time

import redis
# redis = redis.Redis(host='127.0.0.1')
redis1 = redis.Redis(host='192.168.1.65',port=6379,decode_responses=True)
# 订阅者
ps = redis1.pubsub()
ps.subscribe("workflow")

for item in ps.listen():
    if item["type"] == "message":
        time.sleep(5)
        print(item)

# from .task_pub import Intermedia
#
#
# class Subscriber:
#     def __init__(self, name, callback=None):
#         self.name = name
#         self.callback = callback if callable(callback) else self.callback
#     def callback(self, msg):
#         '''当前订阅服务器的默认事件处理程序'''
#         print('Subscriber "{0[name]}" receive message "{0[msg]}" from channel "{0[channel]}"'.format(msg))
#     def subscribe(self, channel):
#         '''从发布服务器订阅特定的通道'''
#         Intermedia.register(channel, self)
#     def unsubscribe(self, channel):
#         '''从出版商取消订阅特定的通道'''
#         Intermedia.unregister(channel, self)
#
# Subscriber("uid1").subscribe("td1")
